// Copyright (C) 2021, Flickering Inc. All rights reserved.
// Author: haiquanchen (haiquanchen@flickering.ai)
const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    // @property({ type: Number, displayName: '亮度' })
    // light: number = 1;

    _light = 1;
    @property({
        range: [0, 5],
        slide: true,
    })
    public get light() {
        return this._light;
    }
    public set light(v: number) {
        this._light = v;
        this.init();
    }

    private _material: cc.MaterialVariant;

    // onLoad () {}

    start() {
        this.init();
    }

    init() {
        if (this.node.getComponent(cc.Label)) {
            this._material = this.node.getComponent(cc.Label).getMaterial(0);
        } else if (this.node.getComponent(cc.Sprite)) {
            this._material = this.node.getComponent(cc.Sprite).getMaterial(0);
        }
        this._material.setProperty('light', this.light);
    }

    // update (dt) {}
}
